package com.aps.algorithm.kpi.excutor;

import com.aps.algorithm.entity.ApsKpiTemplate;
import com.aps.algorithm.kpi.template.DefaultApsKpiTemplateEngine;
import com.aps.common.boot.CoreApplicationContext;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Map;

/**
 * @Author nbZhuozh
 * @Date 2025-11-06  18:12
 **/
public interface KpiTemplateExcutor<T> {


    @SuppressWarnings("unchecked")
    default KpiTemplateExcutor<T> build(String beanName){
        if(StringUtils.isBlank(beanName)){
            return (KpiTemplateExcutor<T>) CoreApplicationContext.getApplicationContext().getBean(DefaultApsKpiTemplateEngine.class);
        }
        if(CoreApplicationContext.getApplicationContext().containsBean(beanName)){
            Object bean = CoreApplicationContext.getApplicationContext().getBean(beanName);
            if(bean instanceof KpiTemplateExcutor<?> kpiTemplateExcutor){
                return (KpiTemplateExcutor<T>) kpiTemplateExcutor;
            }
        }
        return (KpiTemplateExcutor<T>) CoreApplicationContext.getApplicationContext().getBean(DefaultApsKpiTemplateEngine.class);
    }

    Map<String,Object> applay(T data , List<ApsKpiTemplate> template);

}
